<style scoped>
.split {
    height: 600px;
    background: #ffffff;
    border: 1px solid #dcdee2;
}

.split-pane {
    padding: 10px;
}
</style>
<template>
    <div class="split">
        <Split v-model="split1">
            <div slot="left" class="split-pane">
                <Tree :data="treeData" @on-select-change="changeTree"></Tree>
            </div>
            <div slot="right" class="split-pane">
                <Card style="margin-bottom: 10px">
                    <Form inline class="form-search">
                        <FormItem>
                            <Input v-model="keyword" placeholder="姓名/医保号" style="width: 200px" />
                        </FormItem>
                        <FormItem>
                            <Button type="primary" @click=" page = 1; SearchCustomer();" icon="md-search">查询</Button>
                        </FormItem>
                    </Form>
                </Card>
                <Table ref="table" style="margin-bottom: 10px" border :loading="loadingTable" :columns="tableTitle"
                    :data="tableData" :height="tableHeight"></Table>
                <Page :total="total" :current="page" :page-size="size" :page-size-opts="[10]" @on-change="(s) => {
                    page = s; SearchCustomer();
                }" @on-page-size-change="(p) => { size = p; page = 1; SearchCustomer(); }" show-total show-sizer />
                <Modal :footer-hide="true" v-model="modalData" title="新增" :mask-closable="false" draggable sticky>
                    <customeredit :Id="tempDataId" v-if="modalData" @on-success="onSuccess"></customeredit>
                </Modal>
            </div>
        </Split>
    </div>
</template>

<script>
import { SearchCustomer } from '@/api/customer'
import { SearchDepartment, GetTreeDepartment } from '@/api/department'
import { InitDepartmentTree } from '../../libs/tools'
import customeredit from './customeredit.vue'
export default {
    components: { customeredit },
    name: 'customerchose',
    data() {
        return {
            split1: 0.25,
            total: 0,
            page: 1,
            size: 10,
            tableHeight: 450,
            status: -1,
            keyword: '',
            treeData: [],
            selectTreeData: [],
            typeid: 0,
            loadingTable: false,
            tableTitle: [
                {
                    type: 'index',
                    title: '序号',
                    align: 'center',
                    width: 60,
                    // render: (h, params) => {
                    //     return h('span', params.index + (this.page - 1) * this.size + 1)
                    // }
                    indexMethod: (params) => {
                        return params._index + (this.page - 1) * this.size + 1;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    width: 100,
                    render: (h, params) => {
                        return h(
                            'Button',
                            {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.handleChose(params.row)
                                    }
                                }
                            },
                            '选择'
                        )
                    }
                },

                {
                    key: 'DisplayName',
                    title: '姓名',
                    align: 'center'
                },
                {
                    key: 'MedicalCardNo',
                    title: '医保号',
                    align: 'center'
                },
                {
                    key: 'Balance',
                    title: '账户余额',
                    className: 'demo-table-info-column',
                    width: 200,
                    align: 'center',
                    render: (h, params) => {
                        return h(
                            'span',
                            {
                                style: {
                                    color: params.row.Balance > 0 ? '#19be6b' : '#ed4014',
                                    fontSize: '18px'
                                }
                            },
                            params.row.Balance
                        )
                    }
                },
            ],
            tableData: [],
            modalData: false,
            tempDataId: 0
        }
    },
    computed: {},
    methods: {
        onSuccess(res) {
            this.modalData = false
            if (res == 1) {
                this.SearchCustomer()
            }
        },
        handleChose(item) {
            this.$emit('on-success', item)
        },
        GetTreeDepartment() {
            let vm = this
            GetTreeDepartment(0).then((res) => {
                const data = res.data
                if (data.StatusCode == 200) {
                    this.selectTreeData = InitDepartmentTree(data.Data)
                    this.treeData = [
                        {
                            id: 0,
                            label: '全部',
                            title: '全部',
                            value: 0,
                            expand: true,
                            children: this.selectTreeData
                        }

                    ]
                } else {
                    vm.$Message.error({ title: '提示', content: data.Errors })
                }
            })
        },
        SearchCustomer() {
            let vm = this
            vm.loadingTable = true
            var reqData = {
                page: vm.page,
                size: vm.size,
                keyword: vm.keyword,
                typeid: vm.typeid
            }
            SearchCustomer(reqData).then((res) => {
                vm.loadingTable = false
                var data = res.data
                if (data.StatusCode == 200) {
                    vm.tableData = data.Data.Items
                    vm.total = data.Data.TotalCount
                } else {
                    vm.$Notice.error({
                        title: data.Errors
                    })
                }
            })
        },
        AddData() {
            this.tempDataId = 0
            this.modalData = true
        },
        changeTree(a, b) {
            this.typeid = b.id
            this.SearchCustomer()
        },
    },
    mounted() {
        this.GetTreeDepartment();
        this.SearchCustomer()
    }
}
</script>

<style></style>
